/* 2011/4/16 */
using System;
using System.Drawing;

namespace Cosmos.Windows.Themes
{
    public class ClassicTheme : SingleTheme
    {
        public ClassicTheme(ThemeSettings themeSettings)
            : base(themeSettings)
        {

        }

        public override void EnsurePaint()
        {

        }

        public override void CancelPaint()
        {
            
        }

        public override void EndPaint()
        {
            
        }

        public override void PaintImage(bool fastPaint)
        {
            if (_images.Count == 0)
            {
                DrawMessage();
                return;
            }

            Image theImage = Image.FromFile(_images[_imageNumber].Path);
            string theName = _images[_imageNumber].Name;
            string theGroup = _images[_imageNumber].Group;

            double scaleWidth = (double)(theImage.Size.Width) / (double)_size.Width;
            double scaleHeight = (double)(theImage.Size.Height) / (double)_size.Height;

            double scale = Math.Max(scaleWidth, scaleHeight);
            int displayWidth = theImage.Size.Width;
            int displayHeight = theImage.Size.Height;

            if (scale > 1.0)
            {
                displayWidth = (int)((double)displayWidth / scale);
                displayHeight = (int)((double)displayHeight / scale);
            }

            int startX = _random.Next(_size.Width - displayWidth);
            int startY = _random.Next(_size.Height - displayHeight);

            Graphics graphics = _bufferedGraphics.Graphics;
            graphics.Clear(_backColor);
            graphics.DrawImage(theImage, startX, startY, displayWidth, displayHeight);
            DrawFileInformation(graphics, theName, theGroup);
            _bufferedGraphics.Render(Graphics.FromHwnd(_formHandle));

            theImage.Dispose();
        }
    }
}
